* Set working directory and load data
cd "$data_path"
use "dataset", clear

* Define global variables
global wage_controls "female age age2 educ_low_sec educ_high_sec educ_higher tenure tenure2 tenure3 married children lhours"
global weight "w11101"

* Define sample
reg lp0295 t i.land L(0).lagg_ $wage_controls if age<65 & pgisced!=. & age>15 & west==1
gen sample2_used=1 if e(sample)

* Generate state-specific trends
forvalue j=1/16 {
    gen t_la`j'=t*lak`j'
}

* new hire * unemployment rate
gen u_when_new = lagg_*job_change

* labels 
label var lagg_ "Log unemployment rate"
label var u_when_new "Log unemployment rate * new job"
label var mlagg "Log unemployment rate, lagged"

* Column 5: FE
xtset pid svyyear
xtivreg2 lp0295 t t2 lak* lagg_ $wage_controls if sample2_used==1, fe cluster(pid svyyear)
outreg2 lagg_unemp using "$output/Table1.xls",  replace title("Table 1: Estimates of Wage Equations for the UK and Germany") ctitle("Germany (1984-2010)") label addtext(Trend, Quadratic, FE, Yes) keep(lagg_unemp)  nocons coefastr paren se dec(3) excel

* Column 6: New Hire vs Incumbant Wages
xtivreg2 lp0295 t t2 lak* lagg_ job_change u_when_new $wage_controls if sample2_used==1, fe cluster(pid svyyear)
outreg2 lagg_unemp u_when_new using "$output/Table1.xls",  append nocons coefastr paren se dec(3) excel ctitle("Germany (1984-2010)") label addtext(Trend, Quadratic, FE, Yes) keep(lagg_unemp u_when_new)

* Column 7: Spell fixed effects
xtset person_spell_id svyyear
xtivreg2 lp0295 t t2 lak* lagg_ job_change u_when_new $wage_controls if sample2_used==1 , fe cluster(person_spell_id svyyear)
outreg2 lagg_unemp u_when_new using "$output/Table1.xls",   ctitle("Germany (1984-2010)") label addtext(Trend, Quadratic, FE, Spell) keep(lagg_unemp u_when_new)   nocons coefastr paren se dec(3) excel

* Column 8: Lagged u-rate
xtset pid svyyear
xtivreg2 lp0295  t t2 lak* mlagg $wage_controls	if sample2_used==1 , fe cluster(pid svyyear)
outreg2 using "$output/Table1.xls",  ctitle("Germany (1984-2010)") label addtext(Trend, Quadratic, FE, Yes) keep(mlagg)  append nocons coefastr paren se dec(3) excel


